package com.soso.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Table(name="permission")
@Entity
public class Permission {
	
	@Id
	  @Column(name="permissionId",length = 250)
	private String permissionId;
	@JsonIgnoreProperties("permission")

	@ManyToMany(targetEntity = Roles.class,fetch = FetchType.EAGER)//即时加载
	            //指定第三张表的名称                   //指定在中间表中与id的对应关系
	@JoinTable(name="Rolepermission",joinColumns = {@JoinColumn(name="permissionId")},
	//另一张表的主键与中间表的对应关系
	inverseJoinColumns = {@JoinColumn(name="roleId")})
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Roles> roles=new ArrayList<Roles>();
	
	private String permissionValue;
	private String permissionModule;
	private String permissionName;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	private Date permissionLastUpdateTime;
	public Permission(String permissionId, List<Roles> roles, String permissionValue, String permissionModule,
			String permissionName, Date permissionLastUpdateTime) {
		super();
		this.permissionId = permissionId;
		this.roles = roles;
		this.permissionValue = permissionValue;
		this.permissionModule = permissionModule;
		this.permissionName = permissionName;
		this.permissionLastUpdateTime = permissionLastUpdateTime;
	}
	public Permission() {
		super();
	}
	public String getPermissionId() {
		return permissionId;
	}
	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}
	public List<Roles> getRoles() {
		return roles;
	}
	public void setRoles(List<Roles> roles) {
		this.roles = roles;
	}
	public String getPermissionValue() {
		return permissionValue;
	}
	public void setPermissionValue(String permissionValue) {
		this.permissionValue = permissionValue;
	}
	public String getPermissionModule() {
		return permissionModule;
	}
	public void setPermissionModule(String permissionModule) {
		this.permissionModule = permissionModule;
	}
	public String getPermissionName() {
		return permissionName;
	}
	public void setPermissionName(String permissionName) {
		this.permissionName = permissionName;
	}
	public Date getPermissionLastUpdateTime() {
		return permissionLastUpdateTime;
	}
	public void setPermissionLastUpdateTime(Date permissionLastUpdateTime) {
		this.permissionLastUpdateTime = permissionLastUpdateTime;
	}
	@Override
	public String toString() {
		return "Permission [permissionId=" + permissionId + ", roles=" + roles + ", permissionValue=" + permissionValue
				+ ", permissionModule=" + permissionModule + ", permissionName=" + permissionName
				+ ", permissionLastUpdateTime=" + permissionLastUpdateTime + "]";
	}




	
}
